import pathlib
import time

import util

import pandas as pd
import akshare as ak

import model

stockIdx = model.get_zhong_zheng_xiao_fei_index_info()
startPercent = 30   # 回撤达到多少开始网格
step = 5    # 网格步长
perMoney = 1000     # 每份金额

startDate = "20140101"
df = ak.fund_etf_hist_em(symbol=stockIdx.fundList[0].code, start_date=startDate, adjust="qfq")
rs = df.describe()
max, min = rs['最高']['max'], rs['最低']['min']

dataDir = pathlib.Path(f'./data/{stockIdx.name}')
pathlib.Path(dataDir).mkdir(parents=True, exist_ok=True)

df = util.getGridPlanV2(maxValue=max, minValue=min, step=step, startPercent=startPercent, money=perMoney)
print(df)
date = time.strftime('%Y%m%d', time.localtime())
df.to_excel(f'{dataDir}/{stockIdx.name}-{stockIdx.fundList[0].code}-{startPercent}-{step}-{perMoney}-{date}网格计划.xlsx', index=False)

